package com.ruibang.glass.produce.controller.pl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.produce.constant.Constants;
import com.ruibang.glass.produce.domain.req.CommonTrendChartReq;
import com.ruibang.glass.produce.domain.req.GlassFluorescenceReq;
import com.ruibang.glass.produce.domain.req.MainIngredientsRecordReq;
import com.ruibang.glass.produce.domain.resp.MainIngredientsRecordTrendChart;
import com.ruibang.glass.produce.entity.MainIngredientsRecord;
import com.ruibang.glass.produce.service.MainIngredientsRecordService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-03-11  11:27
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "生产-配料-主配料记录控制器")
@RestController
@RequestMapping("/api/glass/produce/pl/mainIngredientsRecord")
public class MainIngredientsRecordController {

    @Autowired
    private MainIngredientsRecordService mainIngredientsRecordService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "查询记录", response = ResultBody.class)
    public ResultBody<IPage<MainIngredientsRecord>> pageQuery(@RequestBody MainIngredientsRecordReq mainIngredientsRecordReq) {
        return ResultBody.success(mainIngredientsRecordService.pageQuery(mainIngredientsRecordReq));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody save(@RequestBody MainIngredientsRecord mainIngredientsRecord) {
        mainIngredientsRecordService.save(mainIngredientsRecord);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "编辑", response = ResultBody.class)
    public ResultBody edit(@RequestBody MainIngredientsRecord mainIngredientsRecord) {
        mainIngredientsRecordService.updateById(mainIngredientsRecord);
        return ResultBody.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody delete(@PathVariable String id) {
        mainIngredientsRecordService.deleteById(id);
        return ResultBody.success();
    }

    @PostMapping("/trendChart")
    @ApiOperation(value = "趋势图", response = ResultBody.class)
    public ResultBody<MainIngredientsRecordTrendChart> trendChart(@RequestBody GlassFluorescenceReq glassFluorescenceReq) {
        return ResultBody.success(mainIngredientsRecordService.trendChart(glassFluorescenceReq));
    }

    @PostMapping("/export")
    @ApiOperation(value = "数据导出")
    public void export(@RequestBody MainIngredientsRecordReq mainIngredientsRecordReq, HttpServletResponse response) {
        mainIngredientsRecordService.export(mainIngredientsRecordReq, response);
    }

}
